package com.tanhua.api.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.api.db.UserApi;
import com.tanhua.domain.db.User;
import com.tanhua.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;



@Service //导入dubbo的注解
public class    UserApiImpl implements UserApi {
    @Autowired
    private UserMapper userMapper;
    @Override
    public Long saveUser(User user) {
            //指定创建和更新时间
        user.setCreated(new Date());
        user.setUpdated(new Date());
        userMapper.insert(user);
        return user.getId();   // 支持主键返回


    }

    @Override
    public User findByPhone(String phone) {
        //创建查询对象
        QueryWrapper<User> qw =new QueryWrapper<>();
        qw.eq("phone",phone);
        return userMapper.selectOne(qw);

    }

}
